﻿using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;

namespace MechAddin.Command.编辑模式
{
    internal static class 编辑模式Model
    {
        public static void 编辑模式(ModelDoc2 swDoc)
        {
            if (swDoc == null) { return; }
            int docType = swDoc.GetType();
            switch (docType)
            {
                case 1:
                    编辑模式1(swDoc); break;
                case 2:
                    编辑模式2(swDoc); break;
                case 3:
                    编辑模式3(swDoc); break;
                default:
                    break;
            }
        }
        private static void 编辑模式1(ModelDoc2 SWDoc )
        {
            SketchManager SkMgr = SWDoc.SketchManager;
            Sketch sk1 = SkMgr.ActiveSketch;
            if (sk1 != null)
            {
                SkMgr.InsertSketch(true);
                return;
            }
            SelectionMgr selMgr = SWDoc.SelectionManager;
            if (selMgr.GetSelectedObjectCount2(-1) == 0) { return; }
            int selType = selMgr.GetSelectedObjectType3(1, -1);
            if (selType == (int)swSelectType_e.swSelSKETCHES)
            {
                SWDoc.EditSketch();
            }
            else
            {
                SWDoc.FeatEditDef();
            }
        }
        private static void 编辑模式2(ModelDoc2 SWDoc)
        {
            AssemblyDoc asm = SWDoc as AssemblyDoc;
            int info = 0;
            int i = asm.EditPart2(true, true, ref info);
            if (i == -1)
            {
                asm.EditAssembly();
            }
        }
        private static void 编辑模式3(ModelDoc2 SWDoc)
        {
            DrawingDoc doc = SWDoc as DrawingDoc;
            if (doc.GetEditSheet())
            {
                doc.EditTemplate();
            }
            else
            {
                doc.EditSheet();
            }
        }
    }
}
